package com.zprmb.udzt;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.zprmb.udzt.ll.BaseHelper;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.LogUtils;
import com.zprmb.udzt.util.VolleryUtil;
import com.zprmb.udzt.view.WebViewDialog;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;



@SuppressLint("SetJavaScriptEnabled")
public class V4WebViewActivity2 extends BaseActivity implements OnClickListener {

    private ImageView iv_v4_web_back;
    private TextView tv_v4_web_title;
    private String title;
    private String ref = "";
    private String url;
    private boolean isOnPause = false;
    private ImageView img_share;
    String version = "";
    private WebView v4_webview;
    private static final String SHARE = "um";
    private RelativeLayout rl_back;
    //	private ProgressBar bar;
    private boolean back = false;
    private WebViewDialog dialog;
    Map<String, String> extraHeaders;
    private SharedPreferences sha;
    int flag;
    private View web_head_view;
    private View title_view;
    private ImageView iv_v4_nonetwork;

    /*
    private TextView img_share;*/
//    private ImageView tv_title;

    //banner的webview
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.banner_webview3);
        setImmersionStatus();
//		Toast.makeText(this, "第二页", Toast.LENGTH_SHORT).show();
        BbtApplication.getInstance().addActvity(this);

        Intent intent = getIntent();
        dialog = new WebViewDialog(this);
//        img_share= (TextView) findViewById(R.id.img_share);
//        img_share.setVisibility(View.GONE);
//        tv_title= (ImageView) findViewById(R.id.tv_title);
//        tv_title.setVisibility(View.GONE);
        title = intent.getStringExtra("title");
//        Toast.makeText(this, title+"", Toast.LENGTH_SHORT).show();


        url = intent.getStringExtra("url");


        ref = getShare().getString("usercode", "");
        version = getAppVersion();
        LogUtils.e(V4WebViewActivity2.this, url);
        // url = "account/invest/8F759CC2-65DB-11E5-AE96-5254002EAABD/contract";
        sha = getSharedPreferences("config", MODE_PRIVATE);
        iv_v4_nonetwork = (ImageView) findViewById(R.id.iv_v4_nonetwork);
        v4_webview = (WebView) findViewById(R.id.v4_webview);
        initView();

        flag = getIntent().getIntExtra("flag", 0);
        if (flag == 1) {
//			 v4_webview.loadUrl("http://192.168.40.154:8085/landing/mNationalDay2016?app=true");
            // v4_webview.loadUrl(Constant.URL+"/h5/expIntro?app=true");
            v4_webview.loadUrl(url + "&token=" + getToken(), extraHeaders);
            Log.e("url", Constant.URL + url + "&token=" + getToken());
            Log.e("url", Constant.URL + url + "&token=" + getToken());
//			v4_webview.loadUrl(url);
        } else {
            v4_webview.loadUrl(Constant.URL + url + "&token=" + getToken(), extraHeaders);
            Log.e("url", Constant.URL + url + "&token=" + getToken());
            // v4_webview.loadUrl("http://192.168.40.177:8085/landing/mWelfare8888-2016");
            Log.e("url", Constant.URL + url + "&token=" + getToken());
        }
        Log.d(url, "------------------");


        v4_webview.resumeTimers();

        if (!network()) {

            iv_v4_nonetwork.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    v4_webview = (WebView) findViewById(R.id.v4_webview);
                    iv_v4_nonetwork.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            v4_webview.reload();
                            initData();
                        }
                    });
                }
            });
            iv_v4_nonetwork.setVisibility(View.VISIBLE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

            v4_webview.setVisibility(View.GONE);
            title_view.setVisibility(View.VISIBLE);
            img_share.setVisibility(View.GONE);
            web_head_view.setVisibility(View.VISIBLE);
//
        } else {

            iv_v4_nonetwork.setVisibility(View.GONE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView

            v4_webview.setVisibility(View.VISIBLE);
            title_view.setVisibility(View.GONE);
            web_head_view.setVisibility(View.VISIBLE);
            initData();
        }


    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        destroyWebView();
        super.onDestroy();

        if (dialog != null) {
            dialog.dismiss();
            dialog = null;
        }
        BbtApplication.getInstance().removeActvity(this);

        handler.removeCallbacksAndMessages(null);
        handler = null;
        setContentView(R.layout.viewxml);
    }

    private void destroyWebView() {
       /* if (v4_webview != null) {
            v4_webview.pauseTimers();
            v4_webview.removeAllViews();
            v4_webview.destroy();
            v4_webview = null;
        }*/
    }

    @Override
    protected void onPause() {
        super.onPause();

        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB && url.contains("video")) {
            v4_webview.onPause(); // 暂停网页中正在播放的视频  
        }
    }

    @Override
    protected void onActivityResult(int arg0, int arg1, Intent arg2) {
        // TODO Auto-generated method stub
        super.onActivityResult(arg0, arg1, arg2);
        if (arg2 != null) {
//			reload=arg1;
//			Log.e("arg1intent", arg2.getIntArrayExtra("resultcode")+"");
            if (arg1 == 1) {

//				String url=geturl().substring(1, geturl().length());
//				Log.e("url", url);
//			v4_webview.loadUrl(Constant.URL+url+"&token="+getURLToken());
                v4_webview.loadUrl(url + "&token=" + getToken(), extraHeaders);
                v4_webview.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        v4_webview.clearHistory();
                    }
                }, 1000);

            } else if (arg1 == 2) {
                v4_webview.reload();
            }
        }
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_BACK) {

            if (v4_webview.canGoBack()) {
                v4_webview.goBack();
            } else {
                finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    WebChromeClient chromeClient = new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {

//    		if (newProgress == 100) {
//				dialog.dismiss();
//			} else {
//				if (dialog.isShowing() == false) {
//					dialog.show();
//				}
//				
//			}
            super.onProgressChanged(view, newProgress);
        }
    };
    private boolean loadError = false;

    private void initData() {
        extraHeaders = new HashMap<String, String>();
        extraHeaders.put("token", getToken());
        v4_webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
//				Log.e("myurl", url+"");
                if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) {
                    if (url.contains("?")) {
                        url = url + "&app=true&token=" + getURLToken();

                    } else {
                        url = url + "?app=true&token=" + getURLToken();

                    }

                    view.loadUrl(url, extraHeaders);
                }

                // else if(url.indexOf("tel")==0){
                // view.loadUrl(url,extraHeaders);
                // return true;
                // }
                // view.loadUrl(Constant.URL_NEW+url,extraHeaders);
                // view.loadUrl("http://docs.google.com/gview?embedded=true&url=http://www.navicat.com.cn/manual/pdf_manual/cn/navicat/rv_manual/rviewer_cs.pdf");
                return true;
            }

            @TargetApi(VERSION_CODES.M)
            @Override
            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                int statusCode = error.getErrorCode();

//                Toast.makeText(V4WebViewActivity2.this, statusCode+"", Toast.LENGTH_SHORT).show();
                loadError = true;
                v4_webview.setVisibility(View.GONE);
                iv_v4_nonetwork.setVisibility(View.VISIBLE);
                title_view.setVisibility(View.GONE);

            }

            @Override
            public void onReceivedSslError(WebView view,
                                           SslErrorHandler handler, SslError error) {
                // TODO Auto-generated method stub
//				super.onReceivedSslError(view, handler, error);
                handler.proceed();
                loadError = true;

//                v4_webview.setVisibility(View.GONE);
//                iv_v4_nonetwork.setVisibility(View.VISIBLE);
//                title_view.setVisibility(View.GONE);
                v4_webview.setVisibility(View.GONE);
                title_view.setVisibility(View.VISIBLE);
                img_share.setVisibility(View.GONE);
                web_head_view.setVisibility(View.VISIBLE);
            }

            @TargetApi(VERSION_CODES.LOLLIPOP)
            @Override
            public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
                int statusCode = errorResponse.getStatusCode();

                Toast.makeText(V4WebViewActivity2.this, statusCode + "", Toast.LENGTH_SHORT).show();

                loadError = true;
                v4_webview.setVisibility(View.GONE);
                iv_v4_nonetwork.setVisibility(View.VISIBLE);
                title_view.setVisibility(View.GONE);
            }

            //			}
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                if (dialog != null & dialog.isShowing() == false) {
                    dialog.show();
                }
                loadError = false;
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
            /*	if (dialog!=null&dialog.isShowing() == true) {
                    dialog.dismiss();

				}
				super.onPageFinished(view, url);*/
                // TODO Auto-generated method stub
                try {

                    if (dialog != null & dialog.isShowing() == true) {
                        dialog.dismiss();

                    }
                    if (!loadError) {//当网页加载成功的时候判断是否加载成功
                        iv_v4_nonetwork.setVisibility(View.GONE);//加载成功的话，则隐藏掉显示正在加载的视图，显示加载了网页内容的WebView
                        v4_webview.setVisibility(View.VISIBLE);
                        title_view.setVisibility(View.GONE);
                        title_view.setVisibility(View.GONE);
                    } else { //加载失败的话，初始化页面加载失败的图，然后替换正在加载的视图页面
//                        iv_v4_nonetwork.setVisibility(View.VISIBLE);
//                        v4_webview.setVisibility(View.GONE);
//                        title_view.setVisibility(View.GONE);
                        v4_webview.setVisibility(View.GONE);
                        title_view.setVisibility(View.VISIBLE);
                        img_share.setVisibility(View.GONE);
                        web_head_view.setVisibility(View.VISIBLE);

                    }
                } catch (Exception e) {

                }


                super.onPageFinished(view, url);
            }

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view,
                                                              String url) {
                // TODO Auto-generated method stub
                return super.shouldInterceptRequest(view, url);

            }
        });
        v4_webview.clearCache(true);

        v4_webview.setWebChromeClient(chromeClient);
        // 重新设置websettings WebSettings s = wb.getSettings();
        // s.setBuiltInZoomControls(true);
        // s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setUseWideViewPort(true);

        v4_webview.getSettings().setLoadWithOverviewMode(true);
        v4_webview.getSettings().setSavePassword(true);
        v4_webview.getSettings().setSaveFormData(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);
        // enable navigator.geolocation
        v4_webview.getSettings().setGeolocationEnabled(true);
        v4_webview.getSettings().setGeolocationDatabasePath(
                "/data/data/org.itri.html5webview/databases/");
        // enable Web Storage: localStorage, sessionStorage
//		v4_webview.getSettings().setDomStorageEnabled(true);
        v4_webview.requestFocus();
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        // v4_webview.setScrollBarStyle(0);
        String ua = v4_webview.getSettings().getUserAgentString();
        v4_webview.getSettings().setUserAgentString(
                ua + "; " + "rmbbox_android");
        v4_webview.addJavascriptInterface(new JsInterfaces(this),
                "AndroidWebView");
        v4_webview.getSettings().setBuiltInZoomControls(true);
        v4_webview.getSettings().setLayoutAlgorithm(
                WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        v4_webview.getSettings().setDomStorageEnabled(true);
        // Set cache size to 8 mb by default. should be more than enough
        v4_webview.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
        // This next one is crazy. It's the DEFAULT location for your app's
        // cache
        // But it didn't work for me without this line.
        // UPDATE: no hardcoded path. Thanks to Kevin Hawkins
        String appCachePath = getApplicationContext().getCacheDir()
                .getAbsolutePath();
        try {
            if (VERSION.SDK_INT >= VERSION_CODES.KITKAT_WATCH) {
                v4_webview.getSettings().setMixedContentMode(v4_webview.getSettings().MIXED_CONTENT_ALWAYS_ALLOW);
            }

        } catch (Exception e) {
            // TODO: handle exception
        }
        v4_webview.getSettings().setAllowFileAccess(true);
        v4_webview.getSettings().setAppCacheEnabled(true);
        v4_webview.getSettings().setJavaScriptEnabled(true);
        v4_webview.getSettings().setAppCachePath(appCachePath);
        v4_webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        v4_webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//		v4_webview.getSettings().setSupportZoom(true);
        v4_webview.getSettings().setDefaultTextEncodingName("utf-8");

    }


    private class JsInterfaces {
        private Context mContext;

        public JsInterfaces(Context context) {
            this.mContext = context;
        }

        // 在js中调用window.AndroidWebView.showInfoFromJs(name)，便会触发此方法。
        @JavascriptInterface
        public void pleaseLogin(String name) {
            Intent intent = new Intent(V4WebViewActivity2.this,
                    V6LoginActivity.class);
            intent.putExtra("close", 1);
            intent.putExtra("web", 1);
            startActivityForResult(intent, 1);
            Editor editor = sha.edit();
            editor.putString("url", url);
            editor.commit();
        }

        @JavascriptInterface
        public void showInfoFromJs(String name) {

            initshare();
        }

        @JavascriptInterface
        public void Tel_phone(String phone) {
            BaseHelper.showDialog2(V4WebViewActivity2.this, "拨号", phone, 1);
        }

        @JavascriptInterface
        public void toproduct(String[] list) {

            // Toast.makeText(Active_Webview.this, list.toString(),
            // 2000).show();

            Intent intent = new Intent(V4WebViewActivity2.this,
                    V6DetailsActivity.class);
            intent.putExtra("flag", Boolean.parseBoolean(list[0]));
            intent.putExtra("name", list[1]);
            intent.putExtra("type", list[2]);
            intent.putExtra("id", list[3]);
            intent.putExtra("isred", list[4]);

            startActivity(intent);
        }

        @JavascriptInterface
        public void switchpage(String name) {


        }

        @JavascriptInterface
        public void jsshare(String sharelink, String description, String title) {
//			Toast.makeText(V4WebViewActivity.this, sharelink+sharelink+title, 2000).show();
            if (sharelink.length() > 1) {
                if (ref.equals("")) {


                } else {
                    sharelink = sharelink + "?ref=" + ref;

                }
                Message message = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("title", title);
                bundle.putString("sharelink", sharelink);
                bundle.putString("description", description);
                bundle.putString("image", description);
                message.setData(bundle);//bundle传值，耗时，效率低
                handler.sendMessage(message);//发送message信息
                message.what = 1;//标志是哪个线程传数据

            }
        }

        @JavascriptInterface
        public void jsshare2(String sharelink, String description, String title, String imageurl) {
//			Toast.makeText(V4WebViewActivity.this, sharelink+sharelink+title, 2000).show();
            if (sharelink.length() > 1) {
                if (ref.equals("")) {


                } else {
                    sharelink = sharelink + "?ref=" + ref;

                }
                Message message = new Message();
                Bundle bundle = new Bundle();
                bundle.putString("title", title);
                bundle.putString("sharelink", sharelink);
                bundle.putString("description", description);
                bundle.putString("imageurl", imageurl);
                message.setData(bundle);//bundle传值，耗时，效率低
                handler.sendMessage(message);//发送message信息
                message.what = 1;//标志是哪个线程传数据

            }
        }

        @JavascriptInterface
        public void finish(int type) {

            if (type == 0) {
                V4WebViewActivity2.this.finish();
                return;

            }
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub

                    if (v4_webview.canGoBack()) {
                        v4_webview.goBack();
                    } else {
                        if (dialog != null) {


                        }
                        Intent intent = new Intent();
                        setResult(1, intent);
                        V4WebViewActivity2.this.finish();
                    }
                }
            });


        }

        @JavascriptInterface
        public void settab(int i) {
            if (MainActivity.instance != null) {
                MainActivity.instance.finish();
            }
            Editor ed = sha.edit();
            ed.putInt("tab", i);
            ed.commit();
            Intent intent = new Intent(V4WebViewActivity2.this,
                    MainActivity.class);
            intent.putExtra("licai", 1);
            startActivity(intent);
        }

        @JavascriptInterface
        public void setTitle(String title) {
            tv_v4_web_title.setText(title);

        }

        @JavascriptInterface
        public void finishActivity() {

            V4WebViewActivity2.this.finish();
        }

        @JavascriptInterface
        public void setactivity(String activity) {


            Intent intent;
            try {
                intent = new Intent(V4WebViewActivity2.this,
                        Class.forName(activity));
                intent.putExtra("webview", 1);
                startActivity(intent);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        @JavascriptInterface
        public void setactivityIntent(String activity, String key, String value) {


            Intent intent;
            try {
                intent = new Intent(V4WebViewActivity2.this,
                        Class.forName(activity));
                intent.putExtra("webview", 1);
                intent.putExtra(key, value);
                startActivity(intent);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        @JavascriptInterface
        public String getApptoken() {
            return getToken();
        }

        @JavascriptInterface
        public String getAppVersionforM() {

            return version;

        }

        @JavascriptInterface
        public void addmoney() {
            verifuser("1");
        }

        public void sendInfoToJs(View view) {
            String msg = getToken();
//			Log.e("web", "调用");
            // 调用js中的函数：showInfoFromJava(msg)

        }
    }

    private void initshare() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                Log.e("invate", jsonObject.toString());
                if (jsonObject.optInt("success") == 1) {
                    JSONObject json = jsonObject.optJSONObject("data");
                    String linkurl = "";
                    if (ref.equals("")) {
                        linkurl = json.optString("linkUrl");

                    } else {
                        linkurl = json.optString("linkUrl") + "?ref=" + ref;

                    }


                    share(V4WebViewActivity2.this, json.optString("description"), json.optString("title"), linkurl, "");
                } else {

                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
//                v4_webview.setVisibility(View.GONE);
//                iv_v4_nonetwork.setVisibility(View.VISIBLE);
                v4_webview.setVisibility(View.GONE);
                iv_v4_nonetwork.setVisibility(View.VISIBLE);
                title_view.setVisibility(View.GONE);

            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.execute(V4WebViewActivity2.this, Constant.URL + "/api/shareProductContent/inviteFriend/inviteFriend", "");
    }

    Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 1) {

                share(V4WebViewActivity2.this, msg.getData().getString("description"), msg.getData().getString("title"), msg.getData().getString("sharelink"), msg.getData().getString("imageurl"));
            }


        }

        ;
    };

    private void verifuser(final String who) {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    JSONObject json = jsonObject.optJSONObject("data");

                    if (json.optBoolean("nameAuth") && json.optBoolean("isBindCard")) {
                        if (who.equals("1")) {
//
                        } else {
                            if (json.optBoolean("payPass")) {

                            } else {
                                Intent intent = new Intent(V4WebViewActivity2.this, Set_tr_pw.class);
                                startActivity(intent);
                            }
                        }
                    } else {

//							if (!json.optBoolean("nameAuth")) {
//								Intent intent = new Intent(AssetsActivity.this,Real_Name.class);
//								startActivity(intent);
//								return;
//							}
                        if (json.optString("bankMobileStatus") != null && !json.optString("bankMobileStatus").equals("") && json.optString("bankMobileStatus").equals("WAIT_CHECK")) {

                        }
                        if (!json.optBoolean("isBindCard")) {
//								!json.optBoolean("isBindCard")

                        }

                    }
                } else {
                    if (jsonObject.optString("comment").equals("please login")) {
                        if (jsonObject.optString("comment").equals("please login")) {
                            Intent intent = new Intent(V4WebViewActivity2.this,
                                    V6LoginActivity.class);
                            intent.putExtra("close", 1);
                            startActivity(intent);
                        }
                    }
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
//                v4_webview.setVisibility(View.GONE);
//                iv_v4_nonetwork.setVisibility(View.VISIBLE);
                v4_webview.setVisibility(View.GONE);
                iv_v4_nonetwork.setVisibility(View.VISIBLE);
                title_view.setVisibility(View.GONE);

            }
        };
        volleryUtil.setRequestMethod(0);
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setShow(true);
        volleryUtil.execute(this, Constant.URL + "/api/v5/user/userInfo", "");
    }

    private void initView() {
        iv_v4_web_back = (ImageView) findViewById(R.id.img_back);
        rl_back = (RelativeLayout) findViewById(R.id.rl_back);
//		bar = (ProgressBar) findViewById(R.id.myProgressBar);
        title_view = (View) findViewById(R.id.title_view);
        img_share = (ImageView) findViewById(R.id.img_share);
        web_head_view = (View) findViewById(R.id.web_head_view);
        img_share.setOnClickListener(this);
        if (title.contains("智投宝")) {
            title_view.setVisibility(View.GONE);

        } else {
            if (getIntent().getIntExtra("banner", 0) == 1) {
                title_view.setVisibility(View.GONE);
                web_head_view.setVisibility(View.VISIBLE);
            } else {
                title_view.setVisibility(View.GONE);
                web_head_view.setVisibility(View.GONE);
            }

        }
        if (getIntent().getIntExtra("share", 0) == 1) {
            img_share.setVisibility(View.GONE);
        }
        rl_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                if (v4_webview.canGoBack()) {
                    v4_webview.goBack();
                } else {
                    finish();
                }
            }
        });
        iv_v4_web_back.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                if (v4_webview.canGoBack()) {
                    v4_webview.goBack();
                } else {
                    finish();
                }
            }
        });
        tv_v4_web_title = (TextView) findViewById(R.id.tv_title);
        tv_v4_web_title.getPaint().setFakeBoldText(true);
        tv_v4_web_title.setText(title);
        if (title.indexOf("了解") == 0) {
            tv_v4_web_title.setText("项目详情");
        } else {

            tv_v4_web_title.setText(title);
        }


    }

    private void shareLogin() {
        VolleryUtil vollery = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    LogUtils.e(V4WebViewActivity2.this, jsonObject.toString());
                    JSONObject json1 = jsonObject.optJSONObject("data");
//					Intent intent = new Intent(V6DetailsActivity.this,
//							WXEntryActivity.class);
//					intent.putExtra("sharelink", json1.optString("linkUrl"));
//					intent.putExtra("description",
//							json1.optString("description"));
//					intent.putExtra("title", json1.optString("title"));
//					intent.putExtra("imgurl", json1.optString("imageUrl"));
//					startActivity(intent);
//					LogUtils.e("url", Constant.URL + "/api/shareProductContent/"
//							+ type + "/" + id);
                    share(V4WebViewActivity2.this, json1.optString("description"), json1.optString("title"), json1.optString("linkUrl"), json1.optString("imageUrl"));
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
                v4_webview.setVisibility(View.GONE);
                iv_v4_nonetwork.setVisibility(View.VISIBLE);
                title_view.setVisibility(View.GONE);

// /                v4_webview.setVisibility(View.GONE);
//                iv_v4_nonetwork.setVisibility(View.VISIBLE);
            }
        };

        vollery.setHeaders("token", getToken());
        vollery.setHeaders("client", "android");
        vollery.setShow(true);
        vollery.setRequestMethod(0);
        vollery.execute(V4WebViewActivity2.this, Constant.URL
                + "/api/shareProductContent/" + getIntent().getStringExtra("type") + "/" + getIntent().getStringExtra("id"), "");
    }

    private void setImmersionStatus() {
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            // 透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // 透明导航栏
            //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.img_share:
                shareLogin();
                break;
        }
    }
}
